--
-- Author: shunguo.chen
-- Date: 2016-10-19 17:42:49
--
-- RewardCodePanel

local ClassRef = app.mvc.createPanelClass(...)
local MAX_WORD_LEN = 20 -- 20个字符

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RewardCodePanel))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end 

function ClassRef:init(data)
	self.super.init(self, data)

	local textField = self._ui["02Status/01input/TextField"]
	self._editText = display.replaceTextFieldWithEditBox(textField)
	self._editText:setMaxLength( MAX_WORD_LEN )

    self._ui.Button:addClickEventListener(function()
	    	local key = self._editText:getText()
	    	local matchStr = string.match(key,"[A-Za-z0-9]+")

			if string.len(key) > 0 then -- 有内容
				if matchStr ~= key then
					app:popMessage( "InvalidRedeemCode" )
				else
					executeFunc(self._onOperate, "useCode", key)
					self._editText:setText("")
				end
			end
		end)
end

function ClassRef:onOperate(cb)
	self._onOperate = cb
end

return ClassRef